package cn.cocho.android.mc.comp.image;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

public class LoadingView extends ImageView {
	
	Animation loadingAnim;

	public LoadingView(Context context) {
		super(context);
		initLoadingAnim();
	}

	public LoadingView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initLoadingAnim();
	}
	
	private void initLoadingAnim(){
		loadingAnim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		LinearInterpolator lin = new LinearInterpolator();
		loadingAnim.setRepeatCount(-1);
		loadingAnim.setDuration(1000);
		loadingAnim.setInterpolator(lin);
		this.startAnimation(loadingAnim);
	}
	
	public void show(){
		this.setVisibility(View.VISIBLE);
		this.startAnimation(loadingAnim);
	}
	
	public void dismiss(){
		this.clearAnimation();
		this.setVisibility(View.GONE);
	}
}
